package club.kingyin.kyblog.core.business.dto;

import lombok.Data;

import java.io.Serializable;

/**
 * @author : kingyin
 * @version : 1.0
 * @program : Ky-Blog
 * @description : 同一响应数据
 * @create : 2021年08月12日 14:49
 **/

@Data
public class ResultUtil implements Serializable {
    private Integer code;
    private String msg;
    private Object data;
    public static ResultUtil success(Object data) {
        return resultData(CodeEnum.SUCCESS.val(), CodeEnum.SUCCESS.msg(), data);
    }

    public static ResultUtil success(Object data, String msg) {
        return resultData(CodeEnum.SUCCESS.val(), msg, data);
    }

    public static ResultUtil fail(Integer code, String msg) {
        return resultData(code, msg, null);
    }

    public static ResultUtil fail(String msg) {
        return resultData(CodeEnum.ERROR.val(), msg, null);
    }

    public static ResultUtil fail(Integer code, String msg, Object data) {
        return resultData(code, msg, data);
    }

    public static ResultUtil resultData(Integer code, String msg, Object data) {
        ResultUtil resultData = new ResultUtil();
        resultData.setCode(code);
        resultData.setMsg(msg);
        resultData.setData(data);
        return resultData;
    }
}
